import Vue from 'vue'
import Router from 'vue-router'
const _import = require('./_import_' + process.env.NODE_ENV)

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '../views/layout/Layout'
import EmptyPage from '../views/layout/EmptyPage'

/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirct in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar,
  }
**/
export const constantRouterMap = [
  { path: '/404', component: _import('errorPage/404'), hidden: true },
  { path: '/401', component: _import('errorPage/401'), hidden: true },
  { path: '/login', component: _import('login/index'), hidden: true },
  {
    path: '',
    component: Layout,
    redirect: 'dashboard',
    children: [
      {
        path: 'dashboard',
        component: _import('dashboard/index'),
        name: 'dashboard',
        meta: { title: 'dashboard', icon: 'dashboard', noCache: true }
      }
    ]
  }
]

export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRouterMap
})

export const asyncRouterMap = [
  {
    path: '/menuManagement',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    name: 'menuManagement',
    meta: {
      title: 'menuManagement',
      noCache: false
    },
    children: [
      {
        path: 'menuManagement',
        component: _import('menuManagement/index'),
        name: 'menuManagement',
        meta: {
          title: 'menuManagement',
          noCache: false
        }
      }
    ]
  },
  {
    path: '/setting',
    component: Layout,
    redirect: 'noredirect',
    name: 'setting',
    meta: {
      title: 'setting',
      icon: 'example',
      auth_rule: '6admin'
    },
    children: [
      {
        path: 'mailerSetting',
        component: _import('setting/mailer/index'),
        name: 'mailerSetting',
        meta: {
          title: 'mailerSetting',
          auth_rule: '15admin'
        }
      },
      {
        path: 'websiteInformation',
        component: _import('setting/websiteInformation/index'),
        name: 'websiteInformation',
        meta: {
          title: 'websiteInformation',
          auth_rule: '71admin'
        }
      },
      {
        path: 'slideManagement',
        component: _import('setting/slideManagement/index'),
        name: 'slideManagement',
        meta: {
          title: 'slideManagement',
          auth_rule: '78admin'
        }
      },
      {
        path: 'pluginManagement',
        component: _import('setting/pluginManagement/index'),
        name: 'pluginManagement',
        meta: {
          title: 'pluginManagement',
          auth_rule: ''
        }
      },
      {
        path: 'uploadSetting',
        component: _import('setting/uploadSetting/index'),
        name: 'uploadSetting',
        meta: {
          title: 'uploadSetting',
          auth_rule: '75admin'
        }
      },
      {
        path: 'fileStorage',
        component: _import('setting/fileStorage/index'),
        name: 'fileStorage',
        meta: {
          title: 'fileStorage',
          auth_rule: '93admin'
        }
      }
    ]
  },
  {
    path: '/userManagement',
    component: EmptyPage,
    redirect: 'noredirect',
    name: 'userManagement',
    meta: {
      title: 'userManagement',
      icon: 'peoples',
      auth_rule: '109user'
    },
    children: [
      {
        path: '/userManagement/managementGroup',
        component: Layout,
        redirect: 'noredirect',
        name: 'managementGroup',
        meta: {
          title: 'managementGroup',
          auth_rule: '49admin'
        },
        children: [
          {
            path: 'roleManagement',
            component: _import('userManagement/managementGroup/roleManagement/index'),
            name: 'roleManagement',
            meta: {
              title: 'roleManagement',
              auth_rule: '50admin'
            }
          },
          {
            path: 'administrator',
            id: '110admin',
            component: _import('userManagement/managementGroup/administrator/index'),
            name: 'administrator',
            meta: {
              title: 'administrator',
              auth_rule: '110admin'
            }
          }
        ]
      },
      {
        path: '/userManagement/userGroup',
        component: Layout,
        redirect: 'noredirect',
        name: 'userGroup',
        meta: {
          title: 'userGroup',
          auth_rule: '152user'
        },
        children: [
          {
            path: 'thisSiteUser',
            component: _import('userManagement/userGroup/thisSiteUser/index'),
            name: 'thisSiteUser',
            meta: {
              title: 'thisSiteUser',
              auth_rule: '153user'
            }
          },
          {
            path: 'theThirdUser',
            component: _import('userManagement/userGroup/theThirdUser/index'),
            name: 'theThirdUser',
            meta: {
              title: 'theThirdUser',
              auth_rule: '156user'
            }
          }
        ]
      }
    ]
  },
  {
    path: '/resourceManagement',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        name: 'resourceManagement',
        component: _import('resourceManagement/index'),
        meta: {
          title: 'resourceManagement',
          icon: 'file',
          noCache: true,
          auth_rule: '150user'
        }
      }
    ]
  },
  {
    path: '/userInfo',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'modifyInfo',
        component: _import('userInfo/modifyInfo'),
        name: 'modifyInfo',
        meta: { title: 'modifyInfo', noCache: true }
      },
      {
        path: 'changePwd',
        component: _import('userInfo/changePwd'),
        name: 'changePwd',
        meta: { title: 'changePwd', noCache: true }
      }
    ]
  },
  {
    path: '/error',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    name: 'errorPages',
    meta: {
      title: 'errorPages',
      icon: '404'
    },
    children: [
      { path: '401', component: _import('errorPage/401'), name: 'page401', meta: { title: 'page401', noCache: true }},
      { path: '404', component: _import('errorPage/404'), name: 'page404', meta: { title: 'page404', noCache: true }}
    ]
  },
  {
    path: '/error-log',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [{ path: 'log', component: _import('errorLog/index'), name: 'errorLog', meta: { title: 'errorLog', icon: 'bug' }}]
  },
  { path: '*', redirect: '/404', hidden: true }
]

